"use strict";
const { app, BrowserWindow, ipcMain, webContents, dialog, systemPreferences, desktopCapturer } = require("electron");
const path = require("path");
require("fs");
process.platform === "darwin";
systemPreferences.getMediaAccessStatus("screen");
systemPreferences.getMediaAccessStatus("camera");
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
const vueProjectAddress = "http://localhost:5173/#";
const createWindow = () => {
  let win = new BrowserWindow({
    minWidth: 1e3,
    minHeight: 600,
    width: 1e3,
    height: 600,
    frame: false,
    // 窗口无边框
    titleBarStyle: "hidden",
    webPreferences: {
      nodeIntegration: true,
      // 渲染进程使用Node API
      contextIsolation: false,
      // 是否开启隔离上下文
      webSecurity: false
    }
  });
  if (process.env.NODE_ENV != "development") {
    win.loadFile(path.join(__dirname, "../dist/index.html"));
  } else {
    win.loadURL(vueProjectAddress);
  }
  win.webContents.openDevTools();
  let videoWin;
  ipcMain.on("open-video", (e, url) => {
    if (videoWin) {
      videoWin.show();
    } else {
      videoWin = new BrowserWindow({
        width: 800,
        height: 500,
        titleBarStyle: "hidden",
        resizable: false,
        // 窗口大小是否可以调整
        webPreferences: {
          nodeIntegration: true,
          contextIsolation: false
        }
      });
      videoWin.on("ready-to-show", () => {
        videoWin.show();
      });
      videoWin.on("close", () => {
        videoWin = null;
      });
    }
    console.log(url);
    const URL = "http://localhost:5173/video?url=" + url;
    videoWin.loadURL(URL);
  });
  ipcMain.on("close-video", () => {
    videoWin.close();
    videoWin = null;
  });
  ipcMain.on("minWin", () => {
    win.minimize();
  });
  ipcMain.on("close", () => {
    app.quit();
  });
};
app.whenReady().then(() => {
  createWindow();
  app.on("activate", () => {
  });
});
app.on("window-all-closed", () => {
  app.quit();
});
